package com.fuda.trade.model
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json

@Serializable
sealed class TradeHoldingData(  ) {

    @Serializable
    data class Money(
        val currency: String?=null, //人民币CNY, 港币HKD, 美元USD
        val total: Double?=null, // 总资产
        val available: Double?=null, // 可用资金
        @SerialName("asset_total")val assetTotal: Double?=null, // 证券资产
        @SerialName("today_profit")val toadyProfit: Double?=null, // 当日参考盈亏
        @SerialName("holding_profit")val holdingProfit: Double?=null, // 持仓盈亏
       ) : TradeHoldingData()

    @Serializable
    data class Share(
        /// 证券名称，采自《国信证券》持仓记录详情
        @SerialName("security_name")val securityName: String?=null,
        /// 持仓盈亏金额，采自《国信证券》持仓记录详情
        @SerialName("profitLoss_amount")val profitLossAmount: Double?=null,
        /// 仓位
        @SerialName("holding_percentage")val holdingPercentage: Double?=null,
        /// 盈亏百分比，采自《国信证券》持仓记录详情
        @SerialName("profit_loss_percentage")val profitLossPercentage: Double?=null,
        /// 当前市值，采自《国信证券》持仓记录详情
        @SerialName("market_value")val marketValue: Double?=null,
        /// 现价，采自《国信证券》持仓记录详情
        @SerialName("current_price")val currentPrice: Double?=null,
        /// 成本基础，采自《国信证券》持仓记录详情
        @SerialName("cost_basis")val costBasis: Double?=null,
        /// 持股数，采自《国信证券》持仓记录详情
        @SerialName("shares_held")val sharesHeld: Int?=null,
        /// 可用股份数，采自《国信证券》持仓记录详情
        @SerialName("available_shares")val availableShares: Int?=null,

        val desc: String?=null,
       ) : TradeHoldingData()

    companion object {
        private val json = Json { encodeDefaults = true }

        fun serialize(command: TradeHoldingData): String {
            return json.encodeToString(command)
        }

        fun deserialize(json: String): TradeHoldingData {
            return Companion.json.decodeFromString(json)
        }

        fun Share(securityName: String, profitLossAmount: Double, sharesHeld: Int, desc: String): TradeHoldingData.Share {
            return Share(securityName,profitLossAmount,10.0, 10.0,123.0,8.8,6.6,sharesHeld,100,desc)
        }
    }
}
